<template>
    <div class='container'>
        <!-- 第一层 -->
        <nav class="login-head">
            <div class="l-h-container">
                <div class="l-h-c-img">
                    <a href="/">
                        <img src="../../assets/logo.png" alt="">
                    </a>
                </div>
                <div class="l-h-c-welcome">
                    <span>
                        欢迎登录
                    </span>
                </div>
            </div>
        </nav>

        <!-- 第二层 -->
        <nav class="login-body">
            <div class="l-b-container">
                <div class="l-b-c-background">

                    <div class="l-b-c-form-box">
                        <span class="msg-tip">
                            <i class="el-icon-warning-outline"></i>
                            我们不会以任何理由要求您转账汇款，谨防诈骗。
                        </span>
                        <div class="chose">
                            <div class="scan-login" style="border-right: 1px solid #f4f4f4;">
                                扫码登录
                            </div>
                            <div class="account-login">
                                账号登陆
                            </div>
                        </div>

                        <div class="submit-info">
                            <div class="msg-wrap">
                                <i class="el-icon-remove-outline"></i>
                                {{ msg }}
                            </div>
                            <div class="account">
                                <i class="el-icon-s-custom"></i>
                                <input v-model="loginVo.account" type="text" placeholder="请输入账号">
                            </div>
                            <div class="password">
                                <i class="el-icon-lock"></i>
                                <input v-model="loginVo.password" type="password" placeholder="请输入密码">
                            </div>
                            <div class="forget-password">
                                <a href="/member/forget">
                                    <span>忘记密码</span>
                                </a>
                            </div>

                            <div class="do-login" @click="doLogin()">
                                <span>登&nbsp;&nbsp;&nbsp;&nbsp;录</span>
                            </div>
                        </div>
                        <!-- other -->
                        <div class="more-login">
                            <div class="other">
                                <div class="do-register">
                                    <span @click="() => { this.$router.push({ path: '/member/register' }) }">
                                        立即注册
                                    </span>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>

            </div>
        </nav>
        <!-- 第三层 -->
        <nav class="login-tail">
            <div class="links">
                <ul>
                    <li><span @click="() => { this.$router.push({ path: '/aboutme' }) }">关于我们</span></li>
                    <li><span @click="() => { this.$router.push({ path: '/contact' }) }">联系我们</span></li>
                    <li><span>人才招聘</span></li>
                    <li><span>友情链接</span></li>
                    <li><span>慕阳社区</span></li>
                </ul>
            </div>

            <div class="copright">
                <span>
                    Copyright © 20023-2024 慕阳muyang.com 版权所有
                </span>
            </div>
        </nav>

    </div>
</template>
<script>
import { getCookie, setCookie } from '../../utils/util';
var exUrl = [
    "/member/register",
    "/member/forget",
    "/member/login",
    "/member/updateEmail",
    "/member/updatePhone",
    "/order/buyproduct",
]
// 导出模块
export default {
    // 模块名字
    name: 'login',
    // 模块数据
    data() {
        //数据
        return {
            loginVo: {
                account: '',   //会员账号
                password: '',   // 会员密码
            },
            msg: "",

        };
    },
    // 里面的函数只有调用才会执行（实时计算）里面是定义的方法
    methods: {
        doLogin() {
            if (this.loginVo.account == "" ||
                this.loginVo.password == "") {
                this.msg = "请输入账号密码"
            }
            this.$http({
                url: this.$http.adornUrl("/shitou-member/shitoumember/member/login"),
                method: 'post',
                data: this.$http.adornData(this.loginVo)
            }).then(({ data }) => {
                if (data.code == 200) {// 登录成功
                    setCookie("memberTicket", data.token)

                    let referrer = document.referrer
                    let tag = false;
                    for (let i = 0; i < exUrl.length; i++) {
                        if (referrer.includes(exUrl[i])) {
                            tag = true;
                            break;
                        }
                    }
                    if (tag) {
                        this.$router.push({ path: '/' })
                    } else {
                        this.$router.go(-1)
                    }

                } else {
                    this.msg = "账号密码错误"
                }
            })
        },
    },

    async created() {
        // let ticket = getCookie("memberTicket")
        // console.log(ticket)
        // if ( ticket != null && ticket != undefined && ticket.length > 0 && ticket != ""){
        //     // this.$router.go(-1)
        // }
    }

};
</script>

<style scoped>
@import url("../../utils/css/login.css");
</style>
